<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <template>
        <div>
          <el-radio-group v-model="queryParams.pend">
             <el-radio-button value="">全部</el-radio-button>
             <el-radio-button label="待下发"></el-radio-button>
             <el-radio-button label="待生产"></el-radio-button>
             <el-radio-button label="生产中"></el-radio-button>
             <el-radio-button label="已完成"></el-radio-button>
             <el-radio-button label="已关闭"></el-radio-button>
             <el-radio-button label="已暂停"></el-radio-button>
          </el-radio-group>
        </div>
      </template>


      <el-form-item label="优先级" prop="orderLevel">
         <el-select v-model="queryParams.orderLevel" placeholder="请选择优先级">
           <el-option label="全部" value=""></el-option>
           <el-option label="普通" value="1"></el-option>
           <el-option label="紧急" value="2"></el-option>
           <el-option label="非常紧急" value="3"></el-option>
           </el-select>
      </el-form-item>


      <el-form-item label="制造方式" prop="method">
            <el-select v-model="queryParams.method" placeholder="请选择制造方式">
                  <el-option label="全部" value=""></el-option>
                   <el-option label="自制件" value="自制件"></el-option>
                   <el-option label="外购件" value="外购件"></el-option>
                   <el-option label="虚拟件" value="虚拟件"></el-option>
                   <el-option label="委外件" value="委外件"></el-option>
            </el-select>
      </el-form-item>



      <el-form-item label="车间" prop="shopId">
        <el-select v-model="queryParams.shopid" placeholder="请选择车间">
          <el-option label="全部" value=""></el-option>
          <el-option label="机械制造车间" value="机械制造车间"></el-option>
          <el-option label="组装车间" value="组装车间"></el-option>
          <el-option label="贴片车间" value="贴片车间"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="生产线" prop="productId">
        <el-select v-model="queryParams.productId" placeholder="请选择生产线">
          <el-option label="全部" value=""></el-option>
          <el-option label="机械加工生产线A" value="机械加工生产线A"></el-option>
          <el-option label="机械加工生产线B" value="机械加工生产线B"></el-option>
          <el-option label="机械加工生产线C" value="机械加工生产线C"></el-option>
          <el-option label="机械加工生产线D" value="机械加工生产线D"></el-option>
        </el-select>
      </el-form-item>




      <el-form-item label="创建时间" prop="creationTime">
        <el-date-picker clearable
          v-model="queryParams.creationTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>

















      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"

        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['sheet:sheet:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['sheet:sheet:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['sheet:sheet:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="sheetList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="工单编号" align="center" prop="worko" />
      <el-table-column label="工单状态" align="center" prop="pend" />
      <el-table-column label="计划开始日期" align="center" prop="startdate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startdate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="计划结束日期" align="center" prop="denddate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.denddate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="优先级" align="center" prop="orderLevel" >
         <template slot-scope="scope">
             <el-tag v-if="scope.row.orderLevel===1">普通</el-tag>
             <el-tag v-if="scope.row.orderLevel===2">紧急</el-tag>
             <el-tag v-if="scope.row.orderLevel===3">非常紧急</el-tag>
         </template>
      </el-table-column>



      <el-table-column label="产品名称" align="center" prop="productName" />
      <el-table-column label="产品编码" align="center" prop="productCode" />
      <el-table-column label="物料类型" align="center" prop="materialtype" />

      <el-table-column label="制造方式" align="center" prop="method" />

      <el-table-column label="计量单位" align="center" prop="unit" />
      <el-table-column label="规格" align="center" prop="specification" />
      <el-table-column label="计划产量" align="center" prop="plannedQuantity" />
      <el-table-column label="完成数量" align="center" prop="pleted" />
      <el-table-column label="车间" align="center" prop="shopId" />
      <el-table-column label="生产线" align="center" prop="productId" />
      <el-table-column label="工艺" align="center" prop="craftId" />
      <el-table-column label="当前工序" align="center" prop="proces" />
      <el-table-column label="订单来源" align="center" prop="dersders" />
      <el-table-column label="生产订单号" align="center" prop="orderId" />
      <el-table-column label="交付日期" align="center" prop="deliveryDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.deliveryDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="销售单号" align="center" prop="orderSell" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="实际开始日期" align="center" prop="artdate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.artdate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="实际结束日期" align="center" prop="enddate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.enddate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="creator" />
      <el-table-column label="创建时间" align="center" prop="creationTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.creationTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['sheet:sheet:edit']"
          >修改</el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['sheet:sheet:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-s-data"
            @click="handleDetail(scope.row)"
            v-hasPermi="['sheet:sheet:aff']"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改生产工单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="工单编号" prop="worko">
          <el-input v-model="form.worko" placeholder="请输入工单编号" />
        </el-form-item>
        <el-form-item label="工单状态" prop="method">
          <el-select v-model="form.pend" placeholder="请选择工单状态">
            <el-option label="全部" value=""></el-option>
            <el-option label="待下发" value="待下发"></el-option>
            <el-option label="待生产" value="待生产"></el-option>
            <el-option label="生产中" value="生产中"></el-option>
            <el-option label="已完成" value="已完成"></el-option>
            <el-option label="已关闭" value="已关闭"></el-option>
            <el-option label="已暂停" value="已暂停"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="计划开始日期" prop="startdate">
          <el-date-picker clearable
            v-model="form.startdate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择计划开始日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="计划结束日期" prop="denddate">
          <el-date-picker clearable
            v-model="form.denddate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择计划结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="优先级" prop="orderLevel">
          <el-select v-model="form.orderLevel" placeholder="请选择优先级">
            <el-option label="全部" value=""></el-option>
            <el-option label="普通" value="1"></el-option>
            <el-option label="紧急" value="2"></el-option>
            <el-option label="非常紧急" value="3"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="产品名称" prop="productName">
          <el-input v-model="form.productName" placeholder="请输入产品名称" />
        </el-form-item>
        <el-form-item label="产品编码" prop="productCode">
          <el-input v-model="form.productCode" placeholder="请输入产品编码" />
        </el-form-item>
        <el-form-item label="制造方式" prop="method">
          <el-select v-model="form.method" placeholder="请选择制造方式">
            <el-option label="全部" value=""></el-option>
            <el-option label="自制件" value="自制件"></el-option>
            <el-option label="外购件" value="外购件"></el-option>
            <el-option label="虚拟件" value="虚拟件"></el-option>
            <el-option label="委外件" value="委外件"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="计量单位" prop="unit">
          <el-input v-model="form.unit" placeholder="请输入计量单位" />
        </el-form-item>
        <el-form-item label="规格" prop="specification">
          <el-input v-model="form.specification" placeholder="请输入规格" />
        </el-form-item>
        <el-form-item label="计划产量" prop="plannedQuantity">
          <el-input v-model="form.plannedQuantity" placeholder="请输入计划产量" />
        </el-form-item>
        <el-form-item label="完成数量" prop="pleted">
          <el-input v-model="form.pleted" placeholder="请输入完成数量" />
        </el-form-item>
        <el-form-item label="车间" prop="shopId">
          <el-select v-model="form.shopId" placeholder="请选择优先级">
            <el-option label="全部" value=""></el-option>
            <el-option label="组装车间" value="1"></el-option>
            <el-option label="
机械制造车间" value="2"></el-option>
            <el-option label="
贴片车间" value="3"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="生产线" prop="productId">
          <el-select v-model="form.productId" placeholder="请选择生产线">
            <el-option label="全部" value=""></el-option>
            <el-option label="机械加工生产线A" value="机械加工生产线A"></el-option>
            <el-option label="机械加工生产线B" value="机械加工生产线B"></el-option>
            <el-option label="机械加工生产线C" value="机械加工生产线C"></el-option>
            <el-option label="机械加工生产线D" value="机械加工生产线D"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="工艺" prop="craftId">
          <el-select v-model="form.craftId" placeholder="请选择生产线">
            <el-option label="全部" value=""></el-option>
            <el-option label="焊接加工通用工艺" value="焊接加工通用工艺"></el-option>
            <el-option label="包装工艺010" value="包装工艺010"></el-option>
            <el-option label="清洗通用工艺003" value="清洗通用工艺003"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="当前工序" prop="proces">
          <el-input v-model="form.proces" placeholder="请输入当前工序" />
        </el-form-item>
        <el-form-item label="订单来源" prop="dersders">
          <el-input v-model="form.dersders" placeholder="请输入订单来源" />
        </el-form-item>
        <el-form-item label="生产订单号" prop="orderId">
          <el-input v-model="form.orderId" placeholder="请输入生产订单号" />
        </el-form-item>
        <el-form-item label="交付日期" prop="deliveryDate">
          <el-date-picker clearable
            v-model="form.deliveryDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择交付日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="销售单号" prop="orderSell">
          <el-input v-model="form.orderSell" placeholder="请输入销售单号" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="实际开始日期" prop="artdate">
          <el-date-picker clearable
            v-model="form.artdate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择实际开始日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="实际结束日期" prop="enddate">
          <el-date-picker clearable
            v-model="form.enddate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择实际结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="创建人" prop="creator">
          <el-input v-model="form.creator" placeholder="请输入创建人" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSheet, getSheet, delSheet, addSheet, updateSheet } from "@/api/sheet/sheet";

export default {
  name: "Sheet",
  data() {
    return {


      shopList:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 生产工单表格数据
      sheetList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        worko: null,
        pend: null,
        startdate: null,
        denddate: null,
        orderLevel: null,
        productName: null,
        productCode: null,
        materialtype: null,
        method: null,
        unit: null,
        specification: null,
        plannedQuantity: null,
        pleted: null,
        shopId: null,
        productId: null,
        craftId: null,
        proces: null,
        dersders: null,
        orderId: null,
        deliveryDate: null,
        orderSell: null,
        artdate: null,
        enddate: null,
        creator: null,
        creationTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {

    handleDetail(row) {
      location.href = '/aff'
    },


    /** 查询生产工单列表 */
    getList() {
      this.loading = true;
      listSheet(this.queryParams).then(response => {
        this.sheetList = response.rows;
        this.total = response.total;
        this.loading = false;
      });

    },



    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        worko: null,
        pend: null,
        startdate: null,
        denddate: null,
        orderLevel: null,
        productName: null,
        productCode: null,
        materialtype: null,
        method: null,
        unit: null,
        specification: null,
        plannedQuantity: null,
        pleted: null,
        shopId: null,
        productId: null,
        craftId: null,
        proces: null,
        dersders: null,
        orderId: null,
        deliveryDate: null,
        orderSell: null,
        remark: null,
        artdate: null,
        enddate: null,
        creator: null,
        creationTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      location.href = '/basic'

      // this.reset();
      // this.open = true;
      // this.title = "添加生产工单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getSheet(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改生产工单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateSheet(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSheet(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除生产工单编号为"' + ids + '"的数据项？').then(function() {
        return delSheet(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('sheet/sheet/export', {
        ...this.queryParams
      }, `sheet_${new Date().getTime()}.xlsx`)
    }
  }
};



</script>

